package ro.ubbcluj.cs.validation.framework.tags.utils;

import java.util.ArrayList;
import java.util.List;

import ro.ubbcluj.cs.validation.framework.core.ParameterName;
import ro.ubbcluj.cs.validation.framework.core.ValidationRule;

public final class ValidatorTagBuilder {

	public static final List<String> buildValidators(String formName, String fieldName, List<ValidationRule> rules){
		List<String> validators = new ArrayList<String>();
		int idx = 1;
		for (ValidationRule r : rules){
			StringBuilder validator = new StringBuilder();
			validator.append("<input type=\"hidden\" ");
			validator.append("name=\""+formName+"validator:"+fieldName+":vidx"+idx+"\" ");
			validator.append("value=\""+r.getType().name()+":");
			for(ParameterName pn : r.getParameters().keySet()){
				validator.append(pn.name()+"="+r.getParameters().get(pn)+";");
			}
			validator.append("\"/>");
			validators.add(validator.toString());
			idx++;
		}
		return validators;
	}
}
